home *** CD-ROM | disk | FTP | other *** search
/ PsL Monthly 1993 December / PSL Monthly Shareware CD-ROM (December 1993).iso / prgmming / dos / pascal / txt132.exe / LEVEL2.PAS < prev    next >
Pascal/Delphi Source File  |  1993-01-23  |  5KB  |  206 lines

  1. {$X+,V-}
  2. program Level2;
  3.  
  4. uses Objects, Drivers, Views, Menus, App, MsgBox;
  5.  
  6. Const
  7.   cmTry = 150;
  8.   cmExec = 151;
  9.   cmOther = 152;
  10.   cm25 = 153;
  11.   cm50 = 154;
  12.  
  13. type
  14.   PDisplayWindow = ^DisplayWindow;
  15.   DisplayWindow = object(Twindow)
  16.     constructor Init;
  17.     end;
  18.  
  19.   PDispInterior = ^DispInterior;
  20.   DispInterior = object(TView)
  21.     procedure Draw; virtual;
  22.     end;
  23.  
  24.   TMyApp = object(TApplication)
  25.     constructor Init;
  26.     procedure Idle; virtual;
  27.     procedure DosShell;
  28.     procedure InitMenuBar; virtual;
  29.     procedure InitStatusLine; virtual;
  30.     procedure HandleEvent(var Event: TEvent); virtual;
  31.     end;
  32.  
  33. var
  34.   DispInt : PDispInterior;
  35.   MyApp: TMyApp;
  36.  
  37. FUNCTION Hex2(B : Byte) : String;
  38. Const
  39.   HexArray : array[0..15] of char = '0123456789ABCDEF';
  40. begin
  41. Hex2[0] := #2;
  42. Hex2[1] := HexArray[B shr 4];
  43. Hex2[2] := HexArray[B and $F];
  44. end;
  45.  
  46. FUNCTION Hex4(W : Word) : String;
  47. begin Hex4 := Hex2(Hi(W))+Hex2(Lo(W)); end;
  48.  
  49. constructor DisplayWindow.Init;
  50. var
  51.   R : TRect;
  52. begin
  53. R.Assign(25,6,54,15);
  54. TWindow.Init(R, 'Info', 0);
  55. Flags := wfMove;
  56. GrowMode := 0;
  57. GetExtent(R);
  58. R.Grow(-1,-1);
  59. DispInt := New(PDispInterior, Init(R));
  60. Insert(DispInt);
  61. end;
  62.  
  63. PROCEDURE DispInterior.Draw;
  64. var S : String[20];
  65. begin
  66. TView.Draw;
  67. Str(ScreenMode, S);
  68. WriteStr(0,1, '  Mode is '+S+'($'+Hex4(ScreenMode)+')', $02);
  69. Str(StartUpMode, S);
  70. WriteStr(0,2, '  StartUpMode is '+S+'($'+Hex4(StartUpMode)+')', $02);
  71. Str(ScreenWidth, S);
  72. WriteStr(0,3, '  Width = '+S, $02);
  73. Str(ScreenHeight, S);
  74. WriteStr(0,4, '  Height = '+S, $02);
  75. if SimulatedMouse then S := 'Simulated' else S := 'Driver';
  76. WriteStr(0,5, '  Mouse is '+S, $02);
  77. end;
  78.  
  79. constructor TMyApp.Init;
  80. begin
  81. TApplication.Init;
  82. if not (Lo(ScreenMode) in [0..3,7]) then
  83.   begin
  84.   StartupMode := Lo(ScreenMode);
  85.   SimMouse;
  86.   end
  87. else StartupMode := ScreenMode;
  88. DeskTop^.Insert(New(PDisplayWindow, Init));
  89. end;
  90.  
  91. procedure TMyApp.DosShell;
  92. begin
  93.   if not (Lo(ScreenMode) in [0..3,7]) then
  94.     DriverMouse;
  95.   TApplication.DosShell;
  96.   if not (Lo(ScreenMode) in [0..3,7]) then
  97.     begin
  98.     ScreenMode := Lo(ScreenMode);  {strip off smFont8x8 bit}
  99.     SimMouse;
  100.     HideMouse;
  101.     ReDraw;
  102.     ShowMouse;
  103.     end;
  104.   DispInt^.DrawView;
  105. end;
  106.  
  107. procedure TMyApp.Idle;
  108. const
  109.   OldMouse : boolean = False;
  110.   OldMode : word = $ffff;
  111. begin
  112. TApplication.Idle;
  113. if (ScreenMode <> OldMode) or (SimulatedMouse <> OldMouse) then
  114.   begin
  115.   OldMouse := SimulatedMouse;
  116.   OldMode := ScreenMode;
  117.   DispInt^.DrawView;
  118.   end;
  119. end;
  120.  
  121. procedure TMyApp.InitMenuBar;
  122. var R: TRect;
  123. begin
  124. GetExtent(R);
  125. R.B.Y := R.A.Y + 1;
  126. MenuBar := New(PMenuBar, Init(R, NewMenu(
  127.   NewSubMenu('~F~ile', hcNoContext, NewMenu(
  128.     NewItem('~D~os', 'AltD', kbAltD, cmExec, hcNoContext,
  129.     NewItem('E~x~it', 'Alt-X', kbAltX, cmQuit, hcNoContext,
  130.     nil))),
  131.   NewSubMenu('~V~ideo', hcNoContext, NewMenu(
  132.     NewItem('~2~5 Line display', 'alt-2', kbAlt2, cm25, hcNoContext,
  133.     NewItem('~4~3/50 Line display', 'alt-5', kbAlt5, cm50, hcNoContext,
  134.     NewItem('~O~ther Mode', 'alt-O', kbAltO, cmOther, hcNoContext,
  135.     nil)))), nil)))));
  136. end;
  137.  
  138. procedure TMyApp.InitStatusLine;
  139. var R: TRect;
  140. begin
  141.   GetExtent(R);
  142.   R.A.Y := R.B.Y - 1;
  143.   StatusLine := New(PStatusLine, Init(R,
  144.     NewStatusDef(0, $FFFF,
  145.       NewStatusKey('~Alt-X~ Exit', kbAltX, cmQuit,
  146.       nil),
  147.     nil)
  148.   ));
  149. end;
  150.  
  151. procedure TMyApp.HandleEvent(var Event: TEvent);
  152. var
  153.   S : string[3];
  154.   Mode, Code : integer;
  155.   Cmd : word;
  156. begin
  157. TApplication.HandleEvent(Event);
  158.  
  159. if (Event.What = evCommand) then
  160.   begin
  161.   case Event.Command of
  162.     cm25 : if ScreenMode <> 3  then
  163.               begin
  164.               DriverMouse;
  165.               SetScreenMode(3);
  166.               end;
  167.     cm50 : if ScreenMode <> $103 then
  168.               begin
  169.               DriverMouse;
  170.               SetScreenMode($103);
  171.               end;
  172.     cmOther :  begin
  173.                S := '';
  174.                repeat
  175.                  Cmd := InputBox('Mode', 'Try which mode', S, 3);
  176.                  if Cmd = cmOK then
  177.                    begin
  178.                    Val(S, Mode, Code);
  179.                    if Code = 0 then
  180.                      if Lo(ScreenMode) <> Mode then
  181.                        begin
  182.                        if Lo(Mode) in [0..3,7] then
  183.                          DriverMouse
  184.                        else SimMouse;
  185.                        HideMouse;
  186.                        SetScreenMode(Mode);
  187.                        if not (Lo(ScreenMode) in [0..3,7]) then
  188.                          ScreenMode := Lo(ScreenMode);  {strip off any smFont8x8 bit}
  189.                        ShowMouse;
  190.                        end;
  191.                    end;
  192.                until (Cmd = cmCancel) or (Code = 0);
  193.                end;
  194.     cmExec :  DosShell;
  195.      end;
  196.   ClearEvent(Event);
  197.   end;
  198. end;
  199.  
  200. begin
  201.   MyApp.Init;
  202.   MyApp.Run;
  203.   MyApp.Done;
  204. end.
  205.  
  206.